import { ImgTxt } from "./ImgTxt";
import { TaskInfo } from "../../../model/TaskInfo";
import { ETaskType } from "../../../../../Message/Game/ETaskType";
import { EventName } from "../../../mvc/EventName";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { GuideType } from "../../../rules/GuideType";
import { ETaskStatus } from "../../../../../Message/Game/ETaskStatus";
import { TaskUtil } from "../TaskUtil";
import { TaskTargetType } from "./TaskTargetType";
import { ETaskGroup } from "../../../../../Message/Game/ETaskGroup";
import { GuideOptType } from "../../../rules/GuideOptType";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { GameController } from "../../../mvc/GameController";
import { GameConst } from "../../../../component/gconst/GameConst";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { Cache } from "../../../cache/Cache";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { ETaskCountType } from "../../../../../Message/Game/ETaskCountType";
import { DailyInfo } from "../../../model/DailyInfo";
import { DailyRule } from "../../../rules/DailyRule";
import { ETaskSubType } from "../../../../../Message/Game/ETaskSubType";
type int = number;
//class TaskProcessPanel
    
    export  class TaskProcessPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._imgTxt = new ImgTxt();
            addChild(this._imgTxt);
            return;
        }

        public updateData(arg1: Object /* flash.text.TextField */, arg2: TaskInfo=null, arg3: Boolean=false, arg4: Function=null, arg5: int=0): void
        {
            var loc4=null;
            this.dispose();
            this._task = arg2;
            this._flyBack = arg4;
            var loc1=this.regExp.exec(arg1.text);
            var loc2=0;
            while (loc1 != null) 
            {
                loc2 = this._imgTxt.bulidPic(loc1, loc2, arg1, "FlyBoot_upSkin", arg3, arg5);
                loc1 = this.regExp.exec(arg1.text);
            }
            loc2 = 0;
            var loc3=this._imgTxt.numChildren;
            while (loc2 < loc3) 
            {
                (loc4 = this._imgTxt.getChildAt(loc2) as Object /* flash.display.Sprite */).addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
                ++loc2;
            }
            arg1.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (!(this._task == null) && this._task.sTask.type == ETaskType._ETaskTypeFightSpirit && arg1.text == EventName.FightSpiritGuideDoingEvent) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FightSpiritShowModule));
                return;
            }
            if (arg1.text == EventName.SpiritEquipGuildEnterCopy) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenCopyWindow, ECopyType._ECopyGuildElite));
                return;
            }
            this.gotoTarget(int(arg1.text));
            return;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.display.Sprite */;
            var loc2=int(loc1.name);
            if (!(this._task == null) && this._task.sTask.guide & GuideType.GuideSpiritEquipCopy && this._task.status == ETaskStatus._ETaskStatusNotCompleted) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenCopyWindow, ECopyType._ECopyGuildElite));
                return;
            }
            if (loc2 != -1) 
            {
                this.coneryTo(loc2);
            }
            if (this._flyBack != null) 
            {
                this._flyBack();
            }
            return;
        }

        /* internal  */gotoTarget(arg1: int): void
        {
            var loc2=null;
            if (!this._task) 
            {
                return;
            }
            var loc1=TaskUtil.getTaskTargetInfo(this._task, arg1);
            if (loc1 == TaskTargetType.CrossTaskModule) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossTaskShowModule));
                return;
            }
            if (loc1 != null) 
            {
                if (this._task.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
                {
                    if (this._task.status == ETaskStatus._ETaskStatusCanGet && !(loc1.targetType == GuideOptType.GuideCycleTaskGet)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21112));
                        return;
                    }
                    if (this._task.status == ETaskStatus._ETaskStatusHadCompleted) 
                    {
                        GameController.cycle.view.show();
                    }
                }
                loc2 = this.getTaskTarget(this._task);
                if (loc2 != this._task) 
                {
                    loc1 = loc2.getTargetByIndex(0);
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskAutoPathReq, {"target": loc1, "task": loc2}));
                if (this._task.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
                {
                    if (!(this._task.status == ETaskStatus._ETaskStatusHadCompleted) && !(this._task.status == ETaskStatus._ETaskStatusCanGet)) 
                    {
                        GameController.cycle.view.hide();
                    }
                }
            }
            return;
        }

        /* internal  */coneryTo(arg1: int): void
        {
            var loc2=null;
            if (!this._task) 
            {
                return;
            }
            var loc1=TaskUtil.getTaskTargetInfo(this._task, arg1);
            if (loc1 == TaskTargetType.CrossTaskModule) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossTaskShowModule));
                return;
            }
            if (this._task.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
            {
                if (this._task.status == ETaskStatus._ETaskStatusCanGet && loc1 && !(loc1.targetType == GuideOptType.GuideCycleTaskGet)) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(21112));
                    return;
                }
                if (this._task.status == ETaskStatus._ETaskStatusHadCompleted) 
                {
                    GameController.cycle.view.show();
                }
            }
            if (loc1 != null) 
            {
                loc2 = this.getTaskTarget(this._task);
                if (loc2 != this._task) 
                {
                    loc1 = loc2.getTargetByIndex(0);
                }
                if (loc1.targetType != GuideOptType.GuideTransportCount) 
                {
                    if (loc1.targetType != GuideOptType.GuideGuildTaskCount) 
                    {
                        if (loc1.targetType != GuideOptType.GuideCentralCount) 
                        {
                            if (loc1.mapId != GameConst.CrossSkyCityMapId) 
                            {
                                if (loc1.mapId != 900801) 
                                {
                                    if (GameMapUtil.isCopyMap(loc1.mapId)) 
                                    {
                                        loc1 = Cache.instance.scene.getNearlyCopyNPC(loc1.mapId);
                                        GameController.guide.clearGuideTimer();
                                        Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": loc1, "task": loc2}));
                                    }
                                    else 
                                    {
                                        Cache.instance.guide.flyGuide = Boolean(loc2.sTask.guide & GuideType.Fly);
                                        GameController.guide.clearGuideTimer();
                                        if (GameMapUtil.curMapState.isCrossCountry) 
                                        {
                                            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskAutoPathReq, {"target": loc1, "task": loc2}));
                                        }
                                        else 
                                        {
                                            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": loc1, "task": loc2}));
                                        }
                                    }
                                }
                                else if (GameMapUtil.isMapById(900801)) 
                                {
                                    Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": loc1, "task": loc2}));
                                }
                                else if (GameController.crossBeach.isInCrossBeachActive) 
                                {
                                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossBeachShowEnterWindow));
                                }
                                else 
                                {
                                    MsgManager.showRollTipsMsg(Language.getString(20328));
                                }
                            }
                            else if (GameMapUtil.isMapById(GameConst.CrossSkyCityMapId)) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": loc1, "task": loc2}));
                            }
                            else if (GameController.skyCity.isInSkyCityActive) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.SkyCityShowEnterWindow));
                            }
                            else 
                            {
                                MsgManager.showRollTipsMsg(Language.getString(20327));
                            }
                        }
                        else 
                        {
                            GameController.guide.clearGuideTimer();
                            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectCentralTask), "task": loc2}));
                        }
                    }
                    else 
                    {
                        GameController.guide.clearGuideTimer();
                        Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": Cache.instance.scene.getGuildTaskNPC()[0], "task": loc2}));
                    }
                }
                else 
                {
                    GameController.guide.clearGuideTimer();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuideFlyReq, {"target": Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectTransport), "task": loc2}));
                }
            }
            if (this._task.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
            {
                if (!(this._task.status == ETaskStatus._ETaskStatusHadCompleted) && !(this._task.status == ETaskStatus._ETaskStatusCanGet)) 
                {
                    GameController.cycle.view.hide();
                }
            }
            return;
        }

        /* internal  */getTaskTarget(arg1: TaskInfo): TaskInfo
        {
            var loc1=null;
            var loc2=null;
            if (arg1.sTask.type == ETaskType._ETaskTypeTaskCount && arg1.status == ETaskStatus._ETaskStatusNotCompleted) 
            {
                loc1 = arg1.sTask.processes[0];
                if (loc1 != null) 
                {
                    var loc3=loc1.contents[0];
                    switch (loc3) 
                    {
                        case ETaskCountType._ETaskCountTypeLoop:
                        {
                            loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupLoopBook);
                            break;
                        }
                        case ETaskCountType._ETaskCountTypeTransport:
                        {
                            loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupTransport);
                            break;
                        }
                        case ETaskCountType._ETaskCountTypeGuildTask:
                        {
                            loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupGuild);
                            break;
                        }
                        case ETaskCountType._ETaskCountTypeCycleTask:
                        {
                            loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupCycle);
                            break;
                        }
                    }
                    if (loc2.length > 0) 
                    {
                        return loc2[0];
                    }
                }
            }
            return arg1;
        }

        /* internal  */getDailyTask(arg1: DailyInfo): TaskInfo
        {
            var loc1=null;
            var loc2=null;
            var loc3=arg1.type;
            switch (loc3) 
            {
                case DailyRule.Transport:
                {
                    loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupTransport);
                    if (loc2 && loc2.length > 0) 
                    {
                        loc1 = loc2[0];
                    }
                    break;
                }
                case DailyRule.CycleTask:
                {
                    loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupLoopBook);
                    if (loc2 && loc2.length > 0) 
                    {
                        loc1 = loc2[0];
                    }
                    break;
                }
                case DailyRule.GuildTask:
                {
                    loc2 = Cache.instance.task.getTaskByGroup(ETaskGroup._ETaskGroupGuild);
                    if (loc2 && loc2.length > 0) 
                    {
                        loc1 = loc2[0];
                    }
                    break;
                }
                case DailyRule.HuntTask:
                {
                    loc2 = Cache.instance.task.getTaskByType(ETaskType._ETaskTypeExplore, ETaskSubType._ETaskSubTypeExploreTreasureHunt);
                    if (loc2 && loc2.length > 0) 
                    {
                        loc1 = loc2[0];
                    }
                    break;
                }
            }
            return loc1;
        }

        public getImgRect(): Object /* flash.geom.Rectangle */
        {
            return this._imgTxt.getImgRect();
        }

        public getTargetRect(arg1: string): Object /* flash.geom.Rectangle */
        {
            return this._imgTxt.getTargetRect(arg1);
        }

        public dispose(): void
        {
            var loc1=null;
            this._task = null;
            this._flyBack = null;
            var loc2=0;
            var loc3=this._imgTxt.numChildren;
            while (loc2 < loc3) 
            {
                loc1 = this._imgTxt.getChildAt(loc2) as Object /* flash.display.Sprite */;
                loc1.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
                ++loc2;
            }
            this._imgTxt.dispose();
            return;
        }

        /* internal */ /* const */regExp: RegExp=new RegExp("@\\d{1}", "g");

        /* internal */ /* var */_imgTxt: ImgTxt;

        /* internal */ /* var */_task: TaskInfo;

        /* internal */ /* var */_flyBack: Function;
    }
